package com.xyzwps.webfluxjava.dependencies;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.joda.JodaModule;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.joda.time.DateTime;
import org.junit.Test;

import java.time.LocalDate;
import java.util.Date;

public class Jackson {

    @Test
    public void mapper() {
        try {
            ObjectMapper mapper = new ObjectMapper()
                    .registerModule(new JavaTimeModule())
                    .registerModule(new JodaModule());
            JSONObject json = new JSONObject();
            json.put("date", new Date());
            json.put("localDate", LocalDate.of(2018, 8, 8));
            json.put("string", "Hello world");
            json.put("joda", DateTime.now());
            String jsonString = mapper.writeValueAsString(json);
            System.out.println(jsonString);

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}